from odoo import api, models, fields


class ProductTemplate(models.Model):
    _inherit = 'product.template'

    s_service_pricing_method = fields.Selection([('panel', 'Panel'), ('area', 'Area')],
                                                compute='_compute_s_service_pricing_method',
                                                inverse='_set_s_service_pricing_method',
                                                string='Subcontracting Pricing Method',
                                                help='外发申请服务计价方式')

    multi_workorder_subcontracting = fields.Boolean(default=False, string='是否多工序委外服务产品',
                                                    compute='_compute_multi_workorder_subcontracting',
                                                    inverse='_set_multi_workorder_subcontracting',
                                                    store=True)

    @api.depends_context('company')
    @api.depends('product_variant_ids.s_service_pricing_method')
    def _compute_s_service_pricing_method(self):
        # Depends on force_company context because standard_price is company_dependent
        # on the product_product
        self._compute_template_field_from_variant_field('s_service_pricing_method')

    def _set_s_service_pricing_method(self):
        self._set_product_variant_field('s_service_pricing_method')

    @api.depends_context('company')
    @api.depends('product_variant_ids.multi_workorder_subcontracting')
    def _compute_multi_workorder_subcontracting(self):
        # Depends on force_company context because standard_price is company_dependent
        # on the product_product
        self._compute_template_field_from_variant_field('multi_workorder_subcontracting')

    def _set_multi_workorder_subcontracting(self):
        self._set_product_variant_field('multi_workorder_subcontracting')



class ProductProduct(models.Model):
    _inherit = 'product.product'

    s_service_pricing_method = fields.Selection([('panel', 'Panel'), ('area', 'Area')], string='Subcontracting Pricing Method')
    multi_workorder_subcontracting = fields.Boolean(default=False, string='是否多工序委外服务产品')
